package com.llkj.qingnianguoxue.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.llkj.qingnianguoxue.R;
import com.llkj.qingnianguoxue.bean.MasterSubcribeBean;

import java.util.List;

/**
 * 大师订阅——支付
 */
public class MasterPayAdapter extends BaseAdapter {
    private Context mContext;
    private List<MasterSubcribeBean.PriceBean> dateData;
    private LayoutInflater mInflater;
    private int mCheckPosition = 0;

    public MasterPayAdapter(Context context, List<MasterSubcribeBean.PriceBean> data) {
        mContext = context;
        mInflater = LayoutInflater.from(context);
        dateData = data;
    }

    public void refreshData(List<MasterSubcribeBean.PriceBean> data) {
        dateData.addAll(data);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return dateData != null ? dateData.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_master_pay, null);
            holder = new ViewHolder();
            holder.tvPay = (TextView) convertView.findViewById(R.id.tv_pay);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        MasterSubcribeBean.PriceBean item = dateData.get(position);
        holder.tvPay.setText(item.getName());
        if (mCheckPosition == position) {
            holder.tvPay.setSelected(true);
        } else {
            holder.tvPay.setSelected(false);
        }
        return convertView;
    }

    public void setCheckPosition(int position) {
        mCheckPosition = position;
        notifyDataSetChanged();
    }

    public int getCheckPosition() {
        return mCheckPosition;
    }

    class ViewHolder {
        TextView tvPay;
    }
}
